package j23;

import cn.hutool.core.thread.ThreadUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chengshuai
 * @date 2021/4/12 21:31
 *
 */
public class JoinDemo {

    /**
     * join方法可以理解为插队，等这些插队的线程都执行完，在执行下面的代码
     * @param args
     */
    public static void main(String[] args) {
        List<Thread> list = new ArrayList();
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(() -> {
                for (int j = 0; j < 10; j++) {
                    ThreadUtil.sleep(100);
                    System.out.println(Thread.currentThread().getName() + "===>" + j);
                }
            }, "t" + i);
            list.add(thread);
        }
        for (Thread t : list) {
            t.start();
        }
        for (Thread t : list) {
            try {
                t.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("线程结束=========");
    }
}
